import 'package:flutter/material.dart';

class CustomPaintFive extends StatelessWidget {
  const CustomPaintFive({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: CustomPaint(
        size: Size(300, 300),
        painter: MyPainter(),
      ),
    );
  }
}

class MyPainter extends CustomPainter {
  double nums = 10;
  @override
  void paint(Canvas canvas, Size size) {
    Rect rect = Offset.zero & size;

    _drawChessBoard(canvas, rect);
  }

  void _drawChessBoard(Canvas canvas, Rect rect) {
    Paint _paint = Paint()
      ..isAntiAlias = true
      ..style = PaintingStyle.fill
      ..color = Color(0xFFDCC48C);

    canvas.drawRect(rect, _paint);
    _paint
      ..style = PaintingStyle.stroke
      ..color = Colors.black
      ..strokeWidth = 2.0;
    canvas.drawRect(rect, _paint);

    _paint
      ..color = Colors.black38
      ..strokeWidth = 1.0;

    for (var i = 0; i <= nums; i++) {
      double dx = rect.left + rect.width / nums * i;
      double dy = rect.top + rect.height / nums * i;

      canvas.drawLine(Offset(rect.left, dy), Offset(rect.right, dy), _paint);

      canvas.drawLine(Offset(dx, rect.top), Offset(dx, rect.bottom), _paint);
    }

    double _radius = rect.width / nums / 2;

    _paint.style = PaintingStyle.fill;

    for (var i = 1; i < nums; i++) {
      for (var j = 1; j < nums; j++) {
        if ((i + j) % 2 == 0) {
          _paint.color = Colors.black;
        } else {
          _paint.color = Colors.white;
        }
        canvas.drawCircle(
            Offset(_radius * 2 * i, _radius * 2 * j), _radius, _paint);
      }
    }
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
